package com.syxp.pda.action.standard;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.syxp.pda.core.web.action.BaseAction;
import com.syxp.pda.entity.standard.CHKType;
import com.syxp.pda.service.standard.CHKTypeService;

public class CHKTypeAction extends BaseAction {
	@Resource
	private CHKTypeService chkTypeService;
	
	private int chkTypeCode;
	private CHKType chkType;
	
	public String load() {
		List list = new ArrayList(); 
		try {
			List<CHKType> types = this.chkTypeService.getDao().getAll();
			for(CHKType o: types) {
				Map map = new HashMap();
				map.put("chkTypeName", o.getChkTypeName());
				map.put("chkTypeCode", o.getChkTypeCode());
				list.add(map);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		this.jsonString = this.gson.toJson(list);
		System.out.println(this.jsonString);
		return SUCCESS;
	}
	
	public String save() {
		try {
			this.chkTypeService.addService(this.chkType);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String delete() {
		try {
			this.chkTypeService.removeService(this.chkTypeCode);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String update() {
		try {
			this.chkTypeService.updateService(this.chkType);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}

	/**
	 * @return the chkTypeService
	 */
	public CHKTypeService getChkTypeService() {
		return chkTypeService;
	}

	/**
	 * @param chkTypeService the chkTypeService to set
	 */
	public void setChkTypeService(CHKTypeService chkTypeService) {
		this.chkTypeService = chkTypeService;
	}

	/**
	 * @return the chkTypeCode
	 */
	public int getChkTypeCode() {
		return chkTypeCode;
	}

	/**
	 * @param chkTypeCode the chkTypeCode to set
	 */
	public void setChkTypeCode(int chkTypeCode) {
		this.chkTypeCode = chkTypeCode;
	}

	/**
	 * @return the chkType
	 */
	public CHKType getChkType() {
		return chkType;
	}

	/**
	 * @param chkType the chkType to set
	 */
	public void setChkType(CHKType chkType) {
		this.chkType = chkType;
	}
	

}
